﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Styx.Common;
using Styx;
using Styx.WoWInternals.WoWObjects;

namespace KingWoW
{
    public partial class KingHealSettingsGUIFORM : Form
    {
        private Styx.Helpers.Settings GuiSettingsBase;
        private string setting_path;
        private string setting_extra_path;
        LocalPlayer Me = null;

        public KingHealSettingsGUIFORM(Styx.Helpers.Settings s, string path, string extra_path, LocalPlayer localPlayer)
        {
            setting_path = path;
            setting_extra_path = extra_path;
            GuiSettingsBase = s;
            InitializeComponent();
            ClassSpecificPropertyGrid.SelectedObject = GuiSettingsBase;
            UtilityGrid.SelectedObject = ExtraUtilsSettings.Instance;
            Me = localPlayer;
        }

        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (setting_path != null)
            {
                GuiSettingsBase.SaveToFile(setting_path);
            }
            if(setting_extra_path!=null)
            {
                ExtraUtilsSettings.Instance.SaveToFile(setting_extra_path);
            }
            this.Close();               
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                Filter = "Setting File|*.xml",
                Title = "Load Setting from a File",
                InitialDirectory = Styx.Common.Utilities.AssemblyDirectory + @"\Routines\king-wow\king-wow-Settings\"
            };
            openFileDialog.ShowDialog();
            if (openFileDialog.FileName.Contains(".xml"))
            {
                try
                {
                    GuiSettingsBase.LoadFromXML(XElement.Load(openFileDialog.FileName));
                    ClassSpecificPropertyGrid.Refresh();
                }
                catch (Exception)
                {

                }
            }
            else
            {
                return;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog
            {
                Filter = "Setting File|*.xml",
                Title = "Save Setting to a File",
                InitialDirectory = Styx.Common.Utilities.AssemblyDirectory + @"\Routines\king-wow\king-wow-Settings\",
                DefaultExt = "xml"
            };

            saveFileDialog.ShowDialog();

            if (saveFileDialog.FileName.Contains(".xml"))
            {
                GuiSettingsBase.SaveToFile(saveFileDialog.FileName);
            }
            else
            {
                return;
            }
        }

        private void KingHealSettingsGUIFORM_FormClosed(object sender, FormClosedEventArgs e)
        {
            Logging.Write("************ XML CONFIGURATION ************");
            Logging.Write(GuiSettingsBase.GetXML().ToString());
            Logging.Write("*******************************************");
            Logging.Write("*******************************************");
            Logging.Write("*******************************************");
            Logging.Write("************ EXTRA CONFIGURATION ************");
            Logging.Write(ExtraUtilsSettings.Instance.GetXML().ToString());
            Logging.Write("*******************************************");
        }

        private void KingHealSettingsGUIFORM_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = Resource1.mage2;
        }

        private void button_full_afk_Click(object sender, EventArgs e)
        {
            if (Me != null)
            {
                switch (Me.Specialization)
                {
                    case WoWSpec.MageArcane:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.arcane_fullAFK));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("FullAFK profile loaded. Use for questing/grind/gather. Movement enabled.");
                        }
                        break;
                    case WoWSpec.MageFrost:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.frost_fullAFK));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("FullAFK profile loaded. Use for questing/grind/gather. Movement enabled.");
                        }
                        break;
                    case WoWSpec.MageFire:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.fire_fullAFK));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("FullAFK profile loaded. Use for questing/grind/gather. Movement enabled.");
                        }
                        break;
                    default:
                        {
                            MessageBox.Show("No default config found for this spec! Set it manually.");
                        }
                        break;
                }
            }
        }

        private void button_Dungeon_Click(object sender, EventArgs e)
        {
            if (Me != null)
            {
                switch (Me.Specialization)
                {
                    case WoWSpec.MageArcane:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.arcane_dungeon));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Dungeon profile loaded. Be sure Hotkey selected match your preference. Pause Hotkey MUST be different from Enyo's or Tyrael's one");
                        }
                        break;
                    case WoWSpec.MageFrost:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.frost_dungeon));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Dungeon profile loaded. Be sure Hotkey selected match your preference. Pause Hotkey MUST be different from Enyo's or Tyrael's one");
                        }
                        break;
                    case WoWSpec.MageFire:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.fire_dungeon));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Dungeon profile loaded. Be sure Hotkey selected match your preference. Pause Hotkey MUST be different from Enyo's or Tyrael's one");
                        }
                        break;
                    default:
                        {
                            MessageBox.Show("No default config found for this spec! Set it manually.");
                        }
                        break;
                }
            }
        }

        private void button_raid_Click(object sender, EventArgs e)
        {
            if (Me != null)
            {
                switch (Me.Specialization)
                {
                    case WoWSpec.MageArcane:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.arcane_raid));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Raid profile loaded. Be sure Hotkey selected match your preference. Pause Hotkey MUST be different from Enyo's or Tyrael's one");
                        }
                        break;
                    case WoWSpec.MageFrost:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.frost_raid));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Raid profile loaded. Be sure Hotkey selected match your preference. Pause Hotkey MUST be different from Enyo's or Tyrael's one");
                        }
                        break;
                    case WoWSpec.MageFire:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.fire_raid));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Raid profile loaded. Be sure Hotkey selected match your preference. Pause Hotkey MUST be different from Enyo's or Tyrael's one");
                        }
                        break;
                    default:
                        {
                            MessageBox.Show("No default config found for this spec! Set it manually.");
                        }
                        break;
                }
            }
        }

        private void button_Quest_Click(object sender, EventArgs e)
        {
            if (Me != null)
            {
                switch (Me.Specialization)
                {
                    case WoWSpec.MageArcane:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.arcane_quest));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Questing profile loaded. Use for questing/grind/gather. Movement disabled.");
                        }
                        break;
                    case WoWSpec.MageFrost:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.frost_questing));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Questing profile loaded. Use for questing/grind/gather. Movement disabled.");
                        }
                        break;
                    case WoWSpec.MageFire:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.fire_quest));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Questing profile loaded. Use for questing/grind/gather. Movement disabled.");
                        }
                        break;
                    default:
                        {
                            MessageBox.Show("No default config found for this spec! Set it manually.");
                        }
                        break;
                }
            }
        }

        private void button_ProvinGround_Click(object sender, EventArgs e)
        {
            if (Me != null)
            {
                switch (Me.Specialization)
                {
                    case WoWSpec.MageArcane:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.arcane_dungeon));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Remember to enable in UTILITY settings tab ProvinGround_Targeting (disable when not in Provinground)");
                        }
                        break;
                    case WoWSpec.MageFrost:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.frost_dungeon));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Remember to enable in UTILITY settings tab ProvinGround_Targeting (disable when not in Provinground)");
                        }
                        break;
                    case WoWSpec.MageFire:
                        {
                            GuiSettingsBase.LoadFromXML(XElement.Parse(Resource1.fire_dungeon));
                            ClassSpecificPropertyGrid.Refresh();
                            MessageBox.Show("Remember to enable in UTILITY settings tab ProvinGround_Targeting (disable when not in Provinground)");
                        }
                        break;
                    default:
                        {
                            MessageBox.Show("No default config found for this spec! Set it manually.");
                        }
                        break;
                }
            }
        }
    }
}
